package com.firexxx.study.performancetest.task;

import com.firexxx.study.performancetest.timeconsume.*;
import lombok.Getter;
import lombok.Setter;

/**
 * 添加通用的时间消耗类操作来模拟业务，用于测试锁、并发性能
 *
 * @author fireXXX
 * @date 2020/11/19 0:14
 **/
public abstract class IFixedTimeConsumeTask extends ITask {

    @Getter
    @Setter
    private ITimeConsume timeConsume;

    @Override
    public void init(Object args) {
        ConsumeTimeArg consumeTaskType = (ConsumeTimeArg)args;

        if (consumeTaskType.getTaskType() == ConsumeTaskType.cpu) {
            timeConsume = new CpuTimeConsume();
        } else {
            timeConsume = new IoTimeConsume();
        }
        timeConsume.setTime(consumeTaskType.getTime());
        setCount(0);
        setPv(0);
        setRunStatus(true);
    }

    public abstract void setCount(long count);

    public abstract long getCount();

    @Override
    public void saveResult(Object obj) {
    }

}